#include "pllistwindow.h"
#include "ui_pllistwindow.h"
#include "publicstruct.h"
#include "mytcpsocket.h"

PLListWindow::PLListWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PLListWindow)
{
    ui->setupUi(this);

    this->setWindowTitle("评论区");
    this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);

    setQssStyle("../style/PlListWindow.qss",this);

    label = new QLabel("暂无评论");
    label->setStyleSheet("font-size:13pt");
    label->setAlignment(Qt::AlignCenter);
    label->setWordWrap(true);

    openNum = 1;


}

PLListWindow::~PLListWindow()
{
    delete ui;
}

void PLListWindow::addPls(QVector<QLabel *> vec)
{
    // 清空所有子控件
    while (QLayoutItem *item = ui->verticalLayout->takeAt(0)) {
        QWidget *widget = item->widget();
        if (widget) {
            widget->setParent(nullptr); // 这将自动从布局中移除控件
//            delete widget; // 删除控件以释放内存
        }
//        delete item; // 删除布局项
    }

    if (vec.size() == 0) {
        ui->verticalLayout->addWidget(label);
        return;
    }

    for(int i = 0;i<vec.size();i++){
        ui->verticalLayout->addWidget(vec[i]);
    }
    ui->verticalLayout->addSpacing(5);
    ui->verticalLayout->addStretch();   // 添加一个可以伸缩的空间
}

void PLListWindow::Show()
{
//    // 如果是第一次打开, 让服务器准备好 动态、评论、点赞 ,提醒我们拉取
//    if(openNum == 1){
//        int uid = GlobalObject::getGlobalObject()->getUserInfo().sdata.dd_num;

//        QVariantMap map;
//        map["cmd"] = "get_dzpl";
//        map["timelineID"] = uid;

//        //发送请求
//        GlobalObject::getGlobalObject()->sendRequest(map);

//        ++openNum;
//    }
    show();
}
